package com.tang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tang.dto.BookDTO;
import com.tang.dto.ImageDTO;
import com.tang.util.DeepBeanUtils;
import com.tang.vo.Book;
import com.tang.vo.Image;
import com.tang.service.ImageService;
import com.tang.mapper.ImageMapper;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author tang
* @description 针对表【image】的数据库操作Service实现
* @createDate 2023-04-30 18:47:33
*/
@Service
public class ImageServiceImpl implements ImageService{

    @Autowired
    private ImageMapper imageMapper;

    @Override
    public List<ImageDTO> all() {
        QueryWrapper<Image> wrapper=new QueryWrapper<>();
        List<Image> images = imageMapper.selectList(wrapper);
        List<ImageDTO> imageDTOS = DeepBeanUtils.copyListProperties(images, ImageDTO::new);
        return imageDTOS;
    }

    @Override
    public int add(ImageDTO imageDTO) {
        if (ObjectUtils.isNotEmpty(imageDTO)){
            Image image = new Image();
            DeepBeanUtils.copyProperties(imageDTO,image);
            return imageMapper.insert(image);
        }
        return 0;
    }

    @Override
    public int delete(String id) {
        return imageMapper.deleteById(id);
    }
}




